#ifndef TEXTURES_H
#define TEXTURES_H

#include "Basic/GxLibBasic.h"
#include "LibGL/GxMath3D.h"

namespace GxRendering
{
	using namespace GxLibBasic;
	class TextureLoadFailedException
	{
	public:
		String FileName;
		TextureLoadFailedException(const String & fname);
	};

	class Texture : public Object
	{
	public:
		enum TextureFilter
		{
			Nearest, Linear, TriLinear,
			Anisotropic4x = 4,
			Anisotropic8x = 8,
			Anisotropic16x = 16
		};
		enum TextureDataType
		{
			Char, Float, RGBE
		};
	protected:
		TextureFilter Filter;
		vec3 AverageRate;
	public:
		String Name;
		unsigned char *Pixels;
		float * PixelsF;
		int Width, Height;
		TextureDataType DataType;
		unsigned int TexID;
		unsigned char Channels; // can be only 3 or 4.
		bool UseHalfFloat;
		Texture();
		~Texture();
		vec3 GetAverageColor();
		void CreateAndUpload();
		void UploadTexture();
		void ReleaseNativeMemory();
		void LoadToMemory(const String & fileName);
		void LoadFromFile(const String & fileName, bool release = true, TextureFilter filter=TriLinear);
		void LoadErrorTexture();
		void SaveToFile(const String & fileName);
		void Bind();
	};
}
#endif